package org.bootstrap.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bootstrap.entity.UserInfo;

import java.util.ArrayList;
import java.util.HashMap;

@Mapper
public interface UserMapper {

    int user_sign(HashMap<String, Object> user);

    String user_login(HashMap<String, String> data); // 返回用户id

    UserInfo user_info(String id); // 返回用户信息

    ArrayList<HashMap<String, Object>> user_search(String keyword);

    int user_exit(String user_id);

    @Update("UPDATE pq_sys.pq_user SET user_avg=#{name} WHERE user_id=#{user_id}")
    int update_avg(@Param("name") String name, @Param("user_id") String user_id);

    @Update("UPDATE pq_sys.pq_user SET name=#{name},content=#{content},pinyin=#{pinyin} WHERE user_id=#{user_id}")
    int info_modify(HashMap<String, String> params);

    @Select("SELECT COUNT(*) FROM pq_sys.pq_user WHERE user_id = #{user_id} AND actor=1 LIMIT 1")
    int is_admin(String user_id);

    @Select("SELECT * FROM pq_sys.pq_user")
    ArrayList<UserInfo> allUsr();

    @Select("SELECT COUNT(*) FROM pq_sys.pq_user WHERE user_id=#{userId} AND password = #{origin} LIMIT 1")
    int verity_password(@Param("userId") String userId, @Param("origin") String origin);

    ArrayList<UserInfo> get_all_users(@Param("start") Integer start, @Param("end") Integer end);

    int modify_password(@Param("userId") String userId, @Param("reInput") String reInput);

    @Update("UPDATE pq_sys.pq_user SET status = #{status} WHERE user_id=#{userId}")
    int set_status(@Param("userId") String userId, @Param("status") int status);
}
